package entity;

import java.util.Map;
import java.util.Objects;

import util.CommonUtil;

public class ConfigEntity {

	public String title, tablename;
	public Object keyword;
	protected Map<String, Object> contentMap;
	
	public ConfigEntity(String title, Map<String, Object> contentMap, String tablename, String idColumn) {
		this.title = title;
		this.contentMap = contentMap;
		this.tablename = tablename;
		this.keyword = CommonUtil.getMapByKeyIgnoreCase(contentMap, idColumn);
	}
	
	public ConfigEntity(String title, String mainColumn, Map<String, Object> contentMap, String tablename, String idColumn) {
		this.title = title + CommonUtil.getMapByKeyIgnoreCase(contentMap, mainColumn);
		this.contentMap = contentMap;
		this.tablename = tablename;
		this.keyword = CommonUtil.getMapByKeyIgnoreCase(contentMap, idColumn);
	}
	
	public void put(String key, Object value) {
		this.contentMap.put(key, value);
	}
	
	public void putIgnoreCase(String key, Object value) {
		CommonUtil.putMapByKeyIgnoreCase(contentMap, key, value);
	}
	
	public Object get(Object key) {
		return this.contentMap.get(key);
	}
	
	public Object getIgnoreCase(Object key) {
		return CommonUtil.getMapByKeyIgnoreCase(contentMap, key.toString());
	}
	
	public Map<String, Object> getContentMap() {
		return contentMap;
	}
	
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return contentMap.toString();
	}

	@Override
	public int hashCode() {
		return Objects.hash(title, tablename, keyword);
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof ConfigEntity)) return false;
		ConfigEntity other = (ConfigEntity) obj;
		return this.tablename.equals(other.tablename) && this.keyword.equals(other.keyword);
	}
	
}

